//
//  InfoModel.swift
//  InfoAPP
//
//  Created by leeco on 2019/5/6.
//  Copyright © 2019 zsw. All rights reserved.
//

import UIKit
import ObjectMapper
import HandyJSON

open class HomeCircle: Mappable {
    
    var title: String
    var link: String
    var pic_arr: Array<Any>
    required public init?(map: Map) {
        title = ""
        link = ""
        pic_arr = []
    }
    
    public func mapping(map: Map) {
        title <- map["title"]
        link <- map["link"]
        pic_arr <- map["pic_arr"]
    }
    
}

class HomeClassifyModel: Mappable {
    
    var title: String
    var link: String
    var pic: String
    required init?(map: Map) {
        title = ""
        link = ""
        pic = ""
    }
    
    func mapping(map: Map) {
        title <- map["title"]
        link <- map["link"]
        pic <- map["pic"]
    }
    
}

class Icon_navigation: Mappable {
    
    var items: Array<IconNavigationModel>
    
    required init?(map: Map) {
        items = []
    }
    
    func mapping(map: Map) {
        items <- map["items"]
    }
    
}

class IconNavigationModel: Mappable {
    var link: String
    var title: String
    var pic :String
    required init?(map: Map) {
        link = ""
        title = ""
        pic = ""
    }
    func mapping(map: Map) {
        link <- map["link"]
        title <- map["title"]
        pic <- map["pic"]
    }
    
}

class HomeListModel: Mappable {
    var link: String
    var title: String
    var publish_time_str: String
    var _type: String
    var show_title: String
    var pics_arr :Array<Any>
    var from :String
    required init?(map: Map) {
        link = ""
        title = ""
        publish_time_str = ""
        _type = ""
        show_title = ""
        pics_arr = Array()
        from = ""
    }
    func mapping(map: Map) {
        link <- map["link"]
        title <- map["title"]
        _type <- map["_type"]
        show_title <- map["show_title"]
        publish_time_str <- map["publish_time_str"]
        pics_arr <- map["pics_arr"]
        
        if pics_arr.count == 0 {
            pics_arr <- map["pic_arr"]
        }
        
        from <- map["from"]
    }
    
}

class ChannelListModel: Mappable {
    
    var name: String!
    var channelId: String!
    var index = 0
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        name <- map["name"]
        channelId       <- map["channelId"]
    }
        
}

class InfoModel: Mappable {
    
    var author_name: String!
    var title: String!
    var url: String!
    var thumbnail_pic_s: String!
    var date: Date!
    
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        author_name <- map["author_name"]
        title       <- map["title"]
        url         <- map["url"]
        thumbnail_pic_s <- map["thumbnail_pic_s"]
        date <- (map["date"],ObjectMapperDateTransform())
    }
}

/***********listModel*************/

class ImageurlModel: Mappable {
    var url: String!
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        url <- map["url"]
    }
    
    
}

class ContentlistModel: Mappable {
    var allList: Array<Any>!
    var id: String!
    var channelId: String!
    var img: String!
    var havePic: Bool!
    var pubDate: Date!
    var title: String!
    var source: String!
    var imageurls: Array<ImageurlModel>!
    var link: String!
    var channelName: String!
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        allList <- map["allList"]
        id <- map["id"]
        channelId <- map["channelId"]
        img <- map["img"]
        img <- map["thumbnail_pic_s"]
        havePic <- map["havePic"]
        imageurls <- map["imageurls"]
        link <- map["link"]
        link <- map["url"]
        title <- map["title"]
        source <- map["source"]
        source <- map["author_name"]
        channelName <- map["channelName"]
        pubDate <- (map["pubDate"],ObjectMapperDateTransform1())
        pubDate <- (map["date"],ObjectMapperDateTransform())
    }
}

class ResponseCircleClassItemModel: Mappable {
    var name: String?
    var id: Int?
    var icon_url: String?
    var link: String?
    var post_today: Int?
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        name <- map["name"]
        link <- map["link"]
        icon_url <- map["icon_url"]
        post_today <- map["post_today"]
    }
}

//逛论坛的数据
class ResponseCircleClassModel: Mappable {
    var name: String?
    var id: Int?
    var circle_list: Array<ResponseCircleClassItemModel>?
    required init?(map: Map) {
    }
    func mapping(map: Map) {
        name <- map["name"]
        id <- map["id"]
        circle_list <- map["circle_list"]
    }
}

//逛论坛的--二级的数据
class ResponseForumDetailListModel: Mappable, CustomStringConvertible {
    var name: String?
    var id: String?
    
    // MARK: - Mappable
    required init?(map: Map) {}
    
    func mapping(map: Map) {
        name <- map["name"]
        id   <- map["id"]
    }
    
    // MARK: - Default initializer
    init(name: String? = nil, id: String? = nil) {
        self.name = name
        self.id = id
    }
    
    // MARK: - Debug description
    var description: String {
        return "ResponseForumDetailListModel(name: \(name ?? "nil"), id: \(id ?? "nil"))"
    }
}

struct PicItem: Codable {
    let url: String?
    let width: Int?  // 根据错误信息，width 是数字类型
    let height: Int? // 如果有的话
    // 其他可能的字段...
}
//逛论坛的--二级的数据
class ResponseForumDetailListDataModel: Codable {
   
    let id: String?
    var title: String?
    var user_name: String?
    var click: String?
    var lastpost: String?
    var pics: [PicItem]?  // 使用专门的模型

    // ... 其他属性
    
    // 如果使用 ObjectMapper，需要添加 Codable 支持
    enum CodingKeys: String, CodingKey {
        case user_name
        case id
        case click
        case title
        case lastpost
        case pics
        // ... 其他属性的 CodingKeys
    }
    
    required init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        user_name = try container.decodeIfPresent(String.self, forKey: .user_name)
        id = try container.decodeIfPresent(String.self, forKey: .id)
        title = try container.decodeIfPresent(String.self, forKey: .title)
        click = try container.decodeIfPresent(String.self, forKey: .click)
        lastpost = try container.decodeIfPresent(String.self, forKey: .lastpost)
        pics = try container.decodeIfPresent([PicItem].self, forKey: .pics)
        // ... 解码其他属性
    }
    
    func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encodeIfPresent(user_name, forKey: .user_name)
        try container.encodeIfPresent(id, forKey: .id)
        // ... 编码其他属性
    }
}
